import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import Login from '../views/Login.vue'
import OnlineServer from '../views/OnlineServer.vue'
import NewsCenter from '../views/NewsCenter.vue'
import WaterChargeQuery from '../views/WaterChargeQuery'
import Payment from '../views/Payment'
import AddAndRepair from '../views/AddAndRepair'
import GetBill from '../views/GetBill'
import Arrears from '../views/Arrears'
import PaymentHistory from '../views/PaymentHistory'
import GetBillDetail from '../views/GetBillDetail'
import RepairAndAdd from '../views/RepairAndAdd'
import Alipay from '../views/Alipay'

Vue.use(VueRouter)

const routes = [{
        path: '/',
        name: 'Home',
        component: Home
    },
    {
        path: '/news/:id/:uid',
        name: 'NewsCenter',
        component: NewsCenter
    },
    {
        path: '/alipay',
        name: 'Alipay',
        component: Alipay
    },
    {
        path: '/login',
        name: 'Login',
        component: Login
    },
    {
        path: '/about',
        name: 'About',
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () =>
            import ( /* webpackChunkName: "about" */ '../views/About.vue')
    },
    {
        path: '/onlineServer',
        name: 'OnlineServer',
        component: OnlineServer
    },
    {
        path: '/paymentHistory',
        name: 'PaymentHistory',
        component: PaymentHistory
    },
    {
        path: '/getBillDetail',
        name: 'GetBillDetail',
        component: GetBillDetail
    },
    {
        path: '/arrears',
        name: 'Arrears',
        component: Arrears
    },
    {
        path: '/waterChargeQuery',
        name: 'WaterChargeQuery',
        component: WaterChargeQuery
    },
    {
        path: '/payment',
        name: 'Payment',
        component: Payment
    },
    {
        path: '/addAndRepair',
        name: 'AddAndRepair',
        component: AddAndRepair
    },
    {
        path: '/repairAndAdd',
        name: 'RepairAndAdd',
        component: RepairAndAdd
    },
    {
        path: '/getBill',
        name: 'GetBill',
        component: GetBill
    }
]

const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes
})

router.beforeEach((to, from, next) => {
    console.log(to);
    console.log("to from");
    console.log(from);
    if (to.fullPath == '/') {
        router.push("/onlineServer");
    } else {
        next();
    }
});

export default router